import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Reducer<WebShareState> buildReducer() {
  return asReducer(
    <Object, Reducer<WebShareState>>{
      WebShareAction.title: _title,
      WebShareAction.progress: _progress,
    },
  );
}

WebShareState _title(WebShareState state, Action action) {
  final WebShareState newState = state.clone()..progress = 100;
  if (newState.title.isEmpty) {
    newState.title = action.payload.replaceAll('"', '');
  }
  return newState;
}

WebShareState _progress(WebShareState state, Action action) {
  final WebShareState newState = state.clone()..progress = action.payload;
  return newState;
}
